package adapter;

import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import bean.GoodsBean;
import bean.GoodsGrade;
import student.andlei.com.student.R;

/**
 * author : ChenHuiMing
 * date : 2018/9/22
 * email : 907399255@qq.com
 * description : 商城年级
 */
public class MallGradeAdapter extends BaseQuickAdapter<GoodsGrade, BaseViewHolder> {

    private GoodsGrade mCheckDegress;

    public MallGradeAdapter(int layoutResId, @Nullable List<GoodsGrade> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, GoodsGrade item) {
        helper.setText(R.id.ctv_subject, item.grade_name);
        if (mCheckDegress == null) {
            if (helper.getAdapterPosition() == 0) {
                helper.setChecked(R.id.ctv_subject, true);
            } else {
                helper.setChecked(R.id.ctv_subject, false);
            }
        } else {
            if (mCheckDegress.grade_id == item.grade_id) {
                helper.setChecked(R.id.ctv_subject, true);
            } else {
                helper.setChecked(R.id.ctv_subject, false);
            }
        }
    }

    public GoodsGrade getCheckDegress() {
        if (mCheckDegress == null && getData() != null && getData().size() > 0) {
            return getData().get(0);
        }
        if (mCheckDegress == null) {
            return new GoodsGrade();
        }
        return mCheckDegress;
    }

    public void setCheckDegress(GoodsGrade checkDegress) {
        mCheckDegress = checkDegress;
    }
}
